package com.goodving.guli.bt.weight;

import android.content.Context;
import android.view.View;

import com.goodving.guli.R;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.ui.PickAdapter;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;

import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;

/**
 * Created by john on 2015/12/9.
 */
public class WeightWrapper { // C1845a
    private static final String f10345b = "WeightWrapper";
    PersonInfo f10346a;
    private int f10347c;
    private WheelView f10348d;
    private PickAdapter f10349e;
    private WheelView f10350f;
    private PickAdapter f10351g;
    private int f10352h;
    private int f10353i;
    private int f10354j;
    private int f10355k;
    private Context f10356l;

    public WeightWrapper(int i, Context context) {
        this.f10354j = 0;
        this.f10355k = 0;
        this.f10347c = i;
        this.f10356l = context;
    }

    public WeightWrapper(PersonInfo personInfo, Context context) {
        this.f10354j = 0;
        this.f10355k = 0;
        this.f10346a = personInfo;
        this.f10356l = context;
        this.f10347c = this.f10346a.height;
    }

    public WeightWrapper(UserInfo userInfo, Context context) {
        this.f10354j = 0;
        this.f10355k = 0;
        this.f10356l = context;
        this.f10347c = userInfo.height;
    }

    private void m14925a(WheelView wheelView, int i) {
        String quantityString;
        int f = wheelView.getRealCurrentItem() + i;
        if (wheelView == this.f10350f) {
            quantityString = this.f10356l.getResources().getQuantityString(R.plurals.numberInch, f, new Object[]{C3657a.f18328f});
        } else {
            quantityString = this.f10356l.getResources().getQuantityString(R.plurals.numberFoot, f, new Object[]{C3657a.f18328f});
        }
        GuliLog.tracePrintInfo(f10345b, "value = " + f + " unit -= " + quantityString);
        wheelView.setCenterStyle(quantityString);
        wheelView.invalidateWheel (false); // m26803b
    }

    class C1846b implements OnWheelScrollListener {
        final /* synthetic */ WeightWrapper f10357a;

        C1846b(WeightWrapper c1845a) {
            this.f10357a = c1845a;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            this.f10357a.m14925a(this.f10357a.f10350f, this.f10357a.f10355k);
        }
    }

    class C1847c implements OnWheelScrollListener {
        final /* synthetic */ WeightWrapper f10358a;

        C1847c(WeightWrapper c1845a) {
            this.f10358a = c1845a;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            this.f10358a.m14929e();
            this.f10358a.m14925a(wheelView, 1);
        }
    }

    private void m14928d() {
        this.f10348d.setVisibility(View.VISIBLE);
        m14929e();
        m14925a(this.f10348d, 1);
        m14925a(this.f10350f, this.f10355k);
        this.f10350f.addScrollingListener(new C1846b(this)); // m26794a
        this.f10348d.addScrollingListener(new C1847c(this));
    }

    private void m14929e() {
        int f = this.f10350f.getRealCurrentItem() + this.f10355k;
        if (this.f10348d.getRealCurrentItem() + 1 == 7) {
            this.f10355k = 0;
            this.f10354j = 6;
        } else if (this.f10348d.getRealCurrentItem() + 1 == 1) {
            this.f10355k = 4;
            this.f10354j = 11;
        } else {
            this.f10355k = 0;
            this.f10354j = 11;
        }
        if (!(this.f10354j == this.f10352h && this.f10355k == this.f10353i)) {
            this.f10351g.m14693c(this.f10355k);
            this.f10351g.m14695d(this.f10354j);
            GuliLog.tracePrintInfo(f10345b, "onScrollingFinished : " + this.f10348d.getRealCurrentItem() + ", invalidate, mInchMin =  " + this.f10355k + ",mInchMax = " + this.f10354j);
            if (f > this.f10354j) {
                f = this.f10354j;
            } else if (f < this.f10355k) {
                f = this.f10355k;
            }
            this.f10350f.setCurrentItem(f - this.f10355k, true); // m26790a
            this.f10350f.invalidateWheel(true); // m26803b
        }
        this.f10352h = this.f10354j;
        this.f10353i = this.f10355k;
    }

    public int m14930a() {
        if (this.f10347c < 0) {
            this.f10347c = C4220a.aC;
        }
        int a = Utils.m7962a(this.f10347c) % 12;
        if (Utils.m7962a(this.f10347c) / 12 <= 1) {
            this.f10355k = 4;
        } else {
            this.f10355k = 0;
        }
        GuliLog.tracePrintInfo(f10345b, "inches = " + a + ", min = " + this.f10355k);
        return a - this.f10355k;
    }

    public void m14931a(WheelView wheelView, PickAdapter dmVar, WheelView wheelView2, PickAdapter dmVar2) {
        this.f10348d = wheelView;
        this.f10349e = dmVar;
        this.f10350f = wheelView2;
        this.f10351g = dmVar2;
        m14928d();
    }

    public int m14932b() {
        return this.f10347c > 0 ? (Utils.m7962a(this.f10347c) / 12) - 1 : 4;
    }

    public int m14933c() {
        int f = this.f10348d.getRealCurrentItem() + 1;
        int f2 = this.f10350f.getRealCurrentItem() + this.f10355k;
        int i = (f * 12) + f2;
        GuliLog.tracePrintInfo(f10345b, "set height : feet = " + f + "inch = " + f2);
        return (int) Math.round(2.54d * ((double) i));
    }
}
